/**
 * Created by tiansha on 2015/10/28.
 */

// stomp over websocket
// Create stomp client over sockJS protocol (see Note 1)
var socket = new SockJS("/hello");
var stompClient = Stomp.over(socket);

// callback function to be called when stomp client is connected to server (see Note 2)
var connectCallback = function() {
    //alert("connected!");
    stompClient.subscribe('/topic/greetings', function(greeting){
        alert(JSON.parse(greeting.body).content);
    });
};

// callback function to be called when stomp client could not connect to server (see Note 3)
var errorCallback = function(error) {
    // display the error's message header:
    alert(error.headers.message);
};

// Connect as guest (Note 4)
stompClient.connect("guest", "guest", connectCallback, errorCallback);

function fnSayHi() {
    stompClient.send("/app/hello", JSON.stringify({ 'name': 'Joe' }));
}